package com.lm.fastjson.controller;

import com.lm.fastjson.entry.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {

    private static final List<User> userList = new ArrayList<>();

    static {
        userList.add(new User(1L, "Tom", "tom@mail.com"));
        userList.add(new User(2L, "Jerry", "jerry@mail.com"));
    }

    @GetMapping
    public List<User> getUsers() {
        return userList; // 自动转 JSON
    }

    @PostMapping
    public String addUser(@RequestBody User user) {
        userList.add(user);
        return "添加成功：" + user.getName();
    }
}
